package servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pojo.GuestDto;
import server.QueryMoneyServer;

public class QueryMoneyServlet extends HttpServlet {
	public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		
		String guestName = "guestName";
		String sex = "sex";
		String roomType = "roomType";
		String tel = "tel";
		String identity = "identity";
		String roomNum = "roomNum";
		String perDay = "perDay";
		String day;
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
		day = df.format(new Date());
		GuestDto gue = new GuestDto();
		List<GuestDto> list = new ArrayList<GuestDto>();
		gue.day = day;
		gue.name = request.getParameter(guestName);
		gue.sex = request.getParameter(sex);
		gue.roomNum = request.getParameter(roomNum);
		gue.roomType = request.getParameter(roomType);
		gue.tel = request.getParameter(tel);
		gue.perDay = request.getParameter(perDay);
		System.out.println("perDay="+gue.perDay);
		System.out.println("roomNum="+gue.roomNum);
		gue.id = request.getParameter(identity);
		
		QueryMoneyServer queryMoney = new QueryMoneyServer();
		List<String> listMoney = queryMoney.getPreMoney(gue.roomNum, gue.perDay);
		HttpSession session = request.getSession();
		if(listMoney == null){
			session.setAttribute("querMoneyMassage", "error");
			response.sendRedirect("/hotel/checkIn.jsp");
		}
		else{
			System.out.println("succeed");
			System.out.println("gue.paid:"+listMoney.get(0)+"gue.perpad:"+listMoney.get(1));
			gue.perPay = listMoney.get(0);
			gue.paid = listMoney.get(1);
			session.setAttribute("querMoneyMassage", "succeed");
			session.setAttribute("fistGuest", gue);
			response.sendRedirect("/hotel/checkIn.jsp");
		}
		
		
	}
	
}
